﻿var EVENTBROKER = {};
EVENTBROKER.gameTopic = new Topic();
EVENTBROKER.menuTopic = new Topic();
EVENTBROKER.matchTopic = new Topic();
EVENTBROKER.keyTopic = new Topic();
EVENTBROKER.gridTopic = new Topic();

EVENTBROKER.topicMap = null;
EVENTBROKER.getTopic = function (cmd) {

    if (EVENTBROKER.topicMap == null) {
        EVENTBROKER.topicMap = {};
        EVENTBROKER.topicMap["game"] = EVENTBROKER.gameTopic;
        EVENTBROKER.topicMap["menu"] = EVENTBROKER.menuTopic;
        EVENTBROKER.topicMap["match"] = EVENTBROKER.matchTopic;
        EVENTBROKER.topicMap["key"] = EVENTBROKER.keyTopic;
        EVENTBROKER.topicMap["grid"] = EVENTBROKER.gridTopic;
        EVENTBROKER.topicMap["screen"] = EVENTBROKER.gridTopic;
    }
    var cmdPrefix = cmd.split('-')[0];
    return EVENTBROKER.topicMap[cmdPrefix];
}

var TOPIC_EVENTS = {};
TOPIC_EVENTS.gameReady = "game-ready";
TOPIC_EVENTS.gameOptionsChanged = "game-options-changed";

TOPIC_EVENTS.menuGo = "menu-go";
TOPIC_EVENTS.menuGoParent = "menu-go-parent";

TOPIC_EVENTS.screenGo = "screen-go";

TOPIC_EVENTS.match = "match";
TOPIC_EVENTS.matchStarting = "match-starting";
TOPIC_EVENTS.matchStarted = "match-started";
TOPIC_EVENTS.matchCompleted = "match-completed";
TOPIC_EVENTS.matchEnded = "match-ended";
TOPIC_EVENTS.matchTimerTick = "match-timer-tick";
TOPIC_EVENTS.matchHelpRequest = "match-help-request";
TOPIC_EVENTS.matchHintResult = "match-hint-result";
TOPIC_EVENTS.matchHintApply = "match-hint-apply";
TOPIC_EVENTS.matchHintClear = "match-hint-clear";
TOPIC_EVENTS.matchRequestNew = "match-request-new";
TOPIC_EVENTS.matchRequestPause = "match-request-pause";
TOPIC_EVENTS.matchRequestResume = "match-request-resume";
TOPIC_EVENTS.matchRequestQuit = "match-request-quit";
TOPIC_EVENTS.matchRequestRestart = "match-request-restart";

TOPIC_EVENTS.key = "key";
TOPIC_EVENTS.keyDisable = "key-disable";
TOPIC_EVENTS.keySwitch = "key-switch";

TOPIC_EVENTS.gridFill = "grid-fill";
TOPIC_EVENTS.gridOnCellSelected = "grid-on-cell-selected";
TOPIC_EVENTS.gridFlashGlowCells = "grid-flash-glow-cells";